package com.hz.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hz.control.CommentControl;
import com.hz.model.Comment;
import com.hz.util.DateControl;

public class AddComment extends HttpServlet {
	private static final long serialVersionUID = 1L;

  @Override
  protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      request.setCharacterEncoding("UTF-8");
      int userId = Integer.parseInt(request.getParameter("userId"));
   // String title = request.getParameter("title");
    //String addtime = request.getParameter("addTime");
    
//    String content = new String(request.getParameter("content").getBytes("ISO-8859-1"),"utf-8");
    String content = request.getParameter("content");
//    System.out.println(content);
    //System.out.println(name);
    Comment comment= new Comment();
    comment.setAddTime(DateControl.Date());
    comment.setContent(content);
    comment.setUserId(userId);
    comment.setTitle("");
    PrintWriter out = response.getWriter();
    if (CommentControl.addComment(comment)) {
      out.print("1");
    } else {
      out.print("0");
    }
  }

  
}
